<%@ page import="java.util.Date" %>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
<%
    //连接数据库参数
    String userName="root";
    String password="12345678";
    String dbName="software1801";
    String host="localhost";
    String port="3306";
    String url="jdbc:mysql://"+host+":"+port+"/"+dbName;
    //创建三个类,
    Connection conn=null; //负责连接数据库的
    Statement statement=null;//负责发送sql语句的
    ResultSet rs=null;  //负责查询结果的

    //注册数据库驱动
    Class.forName("com.mysql.cj.jdbc.Driver");
    //连接数据库
    conn= DriverManager.getConnection(url,userName,password);
    //发送sql语句
    String sql="select * from tbl_user2;";
    statement=conn.createStatement();
    try {
        rs = statement.executeQuery(sql);
        //遍历结果集
        while(rs.next()){
            out.print(rs.getString("t_id")+","+rs.getString("t_name")+","+rs.getString("t_age"));
            out.print("<br>");
        }
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }

%>
</body>
</html>
